package com.jxc.jxc01.grc.web;

import com.jxc.jxc01.grc.entity.Procurement;
import com.jxc.jxc01.grc.service.IProcurementService;
import com.jxc.jxc01.grc.service.impl.ProcurementSreviceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(value = "/addprocurement")
public class AddProcurementServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        // 获取请求数据
        int purchaseId = Integer.parseInt(request.getParameter("purchaseId"));
        String name = request.getParameter("purchaseName");
        String name1 = request.getParameter("goodsName");
        String classs = request.getParameter("classs");
        String name2 = request.getParameter("purchaseSupplierName");
        String unit = request.getParameter("unit");
        String purchaseNum = request.getParameter("purchaseNum");
        double unitPrice = Double.parseDouble(request.getParameter("unitPrice"));
        String totalPrice = request.getParameter("totalPrice");
        String purchaseTime = request.getParameter("purchaseTime");
        String status = request.getParameter("status");
        String note = request.getParameter("note");
        // 封装参数
        Procurement procurement = new Procurement();
        procurement.setPurchaseId(purchaseId);
        procurement.setPurchaseName(name);
        procurement.setGoodsName(name1);
        procurement.setClasss(classs);
        procurement.setPurchaseSupplierName(name2);
        procurement.setUnit(unit);
        procurement.setPurchaseNum(purchaseNum);
        procurement.setUnitPrice(unitPrice);
        procurement.setTotalPrice(totalPrice);
        procurement.setPurchaseTime(purchaseTime);
        procurement.setStatus(status);
        procurement.setNote(note);
        // 调用业务层方法
        IProcurementService iProcurementService = new ProcurementSreviceImpl();
        int i = iProcurementService.addProcurement(procurement);
        // 将处理结果放入request
        if (i > 0) {
            System.out.println(" 成功");
        } else {
            System.out.println("失败");
        }
    }
}
